package com.dwxt.cdms.service;

import com.dwxt.cdms.entity.Customer;
import com.dwxt.cdms.entity.EquipmentCustom;
import com.dwxt.cdms.entity.Warning;
import com.dwxt.cdms.entity.yumeng.LocData;
import com.dwxt.cdms.entity.yumeng.LogData;
import com.dwxt.common.constant.VariableConstants;
import com.dwxt.common.util.SnowIdUtil;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class WatchTwoService {

    @Autowired
    private WarningService warningService;

    @Autowired
    private EquipmentCustomService equipmentCustomService;

    public void receiveData(Object object) {
        JSONObject jsonObject = JSONObject.fromObject(object);
        String devId = jsonObject.getString("devId");
        String stype = jsonObject.getString("stype");
        EquipmentCustom equipmentCustom = equipmentCustomService.selectEquipmentCustomByDeviceIdentity(devId);
        if ("fall".equalsIgnoreCase(stype)) {
            /** 新增sos报警信息 */
            LogData logData = new LogData().setCustomerId(equipmentCustom.getCustomerId());
            warningService.insertWarningBySos(logData);
        }else if("".equalsIgnoreCase(stype)){
            LocData locData = new LocData();
            locData.setDeviceIdentity(devId)
                    //.setTime(DateUtil.timeStrStamp2TimeStr(locData.getTime()))
                    .setId(SnowIdUtil.getInstance().nextId())
                    .setCreateTime(LocalDateTime.now())
                    .setIsDelete(VariableConstants.STRING_CONSTANT_0);
            warningService.insertWarningElectronic(locData);
        }
    }
}
